package com.tarim.wheat.service.impl;

import com.tarim.wheat.mapper.TypeMapper;
import com.tarim.wheat.model.Type;
import com.tarim.wheat.service.InformationService;
import com.tarim.wheat.service.TypeService;
import com.tarim.wheat.vo.Criteria;
import com.tarim.wheat.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    TypeMapper typeMapper;
    @Autowired
    InformationService informationService;

    @Override
    public List selectAll() {
        return typeMapper.selectAll();
    }

    @Override
    public List selectByCondition(Type type) {
        Criteria criteria = new Criteria();
        PageBean pageBean = new PageBean(1, 5);
        List<Type> list = typeMapper.selectByCondition(type);
        for (int i=0; i<list.size(); i++){
            criteria.addExtField("typeId", list.get(i).getId());
            pageBean = informationService.selectByCondition(criteria, pageBean);
            list.get(i).setInformationList(pageBean.getResultList());
        }
        return list;
    }
}
